<?php

$sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);

socket_connect($sock, '0.0.0.0', 9501);

while(($buf = socket_read($sock, 2048)) !== false) {
    if (! $buf) {
        var_dump($buf . "\n");
        break;
    }
    file_put_contents('receive.png', $buf, FILE_APPEND);
}

echo "receive file data \n";
socket_write($sock, "Thank you");
socket_close($sock);
